package com.codingxyz.simple.stream;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class StreamDemo {

    public static void main(String[] args) {

        Map map1 = new HashMap();
        map1.put("userid",10001);
        map1.put("userName","Maple");
        Map map2 = new HashMap();
        map2.put("userid",10002);
        map2.put("userName","Jack");
        Map map3 = new HashMap();
        map3.put("userid",10003);
        map3.put("userName","MayLi");
        List<Map> maps = Arrays.asList(map1,map2,map3);

        StreamDemo streamDemo = new StreamDemo();

        List<User> list =streamDemo.getUserList(maps);

        System.out.println(list.toString());

    }

    public List<User> getUserList(List<Map> maps){
        return  maps.stream().map(x->{
            User user = new User();
            user.setUserid((Integer) x.get("userid"));
            user.setUserName((String) x.get("userName"));
            return user;
        }).collect(Collectors.toList());
    }
}
